package cn.com.pureAppApi.serviceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.List;
import java.util.ArrayList;

import cn.com.pureAppApi.utils.PageUtils;
import cn.com.pureAppApi.utils.Query;

import cn.com.pureAppApi.entity.UserEntity;
import cn.com.pureAppApi.service.IUserService;
import cn.com.pureAppApi.dao.UserMapper;
import cn.com.pureAppApi.entity.vo.UserEntityVo;


import com.github.pagehelper.PageHelper;
import cn.com.pureAppApi.utils.ResponseResult;


/**
 * 接口实现ServiceImpl
 * 用户; InnoDB free: 10240 kB
 *
 * QQ讨论群:76989293
 * @email 2696701142@qq.com
 * @date 2018-06-12 16:55:08
 */
@Service
public class UserServiceImpl   implements IUserService {

	@Autowired
	private UserMapper themapper;
	
	@Override
	public List<UserEntityVo> findListPageVo(Integer page, Integer rows) {	
		UserEntity record= new UserEntity();
		PageHelper.startPage(page, rows, false);
		List<UserEntity> list = themapper.select(record);		
		List<UserEntityVo> listVo = new ArrayList<UserEntityVo>();
		if(list!=null && list.size()>0){
			for (UserEntity entity : list) {
			UserEntityVo vo  =new UserEntityVo();
					vo.setUserId(entity.getUserId());//  
					vo.setUsername(entity.getUsername());// 用户名 
					vo.setMobile(entity.getMobile());// 手机号 
					vo.setPassword(entity.getPassword());// 密码 
					vo.setCreateTime(entity.getCreateTime());// 创建时间 
					listVo.add(vo);
			}
		}
		return listVo;
		//分页查询		

	}
	
	@Override
	public List<UserEntityVo> findListPageVoByParamId(Integer page, Integer rows,Long oneByParamId) {	
		UserEntity record= new UserEntity();
		//record.setId(oneByParamId);
		PageHelper.startPage(page, rows, false);
		List<UserEntity> list = themapper.select(record);		
		List<UserEntityVo> listVo = new ArrayList<UserEntityVo>();
		if(list!=null && list.size()>0){
			for (UserEntity entity : list) {
				UserEntityVo vo  =new UserEntityVo();
							vo.setUserId(entity.getUserId());//  
							vo.setUsername(entity.getUsername());// 用户名 
							vo.setMobile(entity.getMobile());// 手机号 
							vo.setPassword(entity.getPassword());// 密码 
							vo.setCreateTime(entity.getCreateTime());// 创建时间 
							listVo.add(vo);
			}
		}
		return listVo;
	}
	
	@Override
	public UserEntityVo findSelectOneVoByParamId(Long oneByParamId) {	
			UserEntity record= new UserEntity();
			//record.setId(oneByParamId);		
			UserEntity entity = themapper.selectOne(record);		
			UserEntityVo vo  =new UserEntityVo();
			if(entity!=null ){
					vo.setUserId(entity.getUserId());//  
					vo.setUsername(entity.getUsername());// 用户名 
					vo.setMobile(entity.getMobile());// 手机号 
					vo.setPassword(entity.getPassword());// 密码 
					vo.setCreateTime(entity.getCreateTime());// 创建时间 
						}
			return vo;
	}
	
	@Override
   	public UserEntityVo insertReturnVo(UserEntityVo vo){
   		if (null==vo) {
			ResponseResult.error();
		}
		UserEntity record= new UserEntity();
		if(vo!=null){
		record.setUserId(vo.getUserId());//  
		record.setUsername(vo.getUsername());// 用户名 
		record.setMobile(vo.getMobile());// 手机号 
		record.setPassword(vo.getPassword());// 密码 
		record.setCreateTime(vo.getCreateTime());// 创建时间 
			}
		themapper.insertSelective(record);
		return vo;
   	}
   	
   	@Override
   	public UserEntityVo editReturnVo(UserEntityVo vo){
   		if (null==vo) {
			ResponseResult.error();
		}
		UserEntity record= new UserEntity();
		if(vo!=null){
			record.setUserId(vo.getUserId());//  
			record.setUsername(vo.getUsername());// 用户名 
			record.setMobile(vo.getMobile());// 手机号 
			record.setPassword(vo.getPassword());// 密码 
			record.setCreateTime(vo.getCreateTime());// 创建时间 
				}
		themapper.updateByPrimaryKeySelective(record);
		return vo;
   	}
   	
	@Override
	public List<UserEntity> findListPage(Integer page, Integer rows) {
		//分页查询		
		UserEntity record= new UserEntity();
		PageHelper.startPage(page, rows, false);
		List<UserEntity> list = themapper.selectAll();		
		return list;
	}
	
	@Override
	public List<UserEntity>findListByParamId(Integer page, Integer rows,Long oneByParamId){
		//分页查询		
		UserEntity record= new UserEntity();
		//record.setId(oneByParamId)
		PageHelper.startPage(page, rows, false);
		List<UserEntity> list = themapper.select(record);		
		return list;
	}
 
   	 
   	@Override
   	public UserEntity insert(UserEntity vo){
   		if (null==vo) {
			ResponseResult.error();
		}
		UserEntity record= new UserEntity();
		if(vo!=null){
		record.setUserId(vo.getUserId());//  
		record.setUsername(vo.getUsername());// 用户名 
		record.setMobile(vo.getMobile());// 手机号 
		record.setPassword(vo.getPassword());// 密码 
		record.setCreateTime(vo.getCreateTime());// 创建时间 
			}
		themapper.insertSelective(record);
		return vo;
   	}
   	
   	@Override
   	public UserEntity edit(UserEntity vo){
   		if (null==vo) {
			ResponseResult.error();
		}
		UserEntity record= new UserEntity();
		if(vo!=null){
		record.setUserId(vo.getUserId());//  
		record.setUsername(vo.getUsername());// 用户名 
		record.setMobile(vo.getMobile());// 手机号 
		record.setPassword(vo.getPassword());// 密码 
		record.setCreateTime(vo.getCreateTime());// 创建时间 
			}
		themapper.updateByPrimaryKeySelective(record);
		return vo;
   	}
   	
   	@Override
	public int save(UserEntity vo){
		if (null==vo) {
			ResponseResult.error();
		}
		UserEntity record= new UserEntity();
		if(vo!=null){
		record.setUserId(vo.getUserId());//  
		record.setUsername(vo.getUsername());// 用户名 
		record.setMobile(vo.getMobile());// 手机号 
		record.setPassword(vo.getPassword());// 密码 
		record.setCreateTime(vo.getCreateTime());// 创建时间 
			}
		return themapper.insertSelective(record);
	}
	
	@Override
	public int update(UserEntity vo){
		if (null==vo) {
			ResponseResult.error();
		}
		UserEntity record= new UserEntity();
		if(vo!=null){
		record.setUserId(vo.getUserId());//  
		record.setUsername(vo.getUsername());// 用户名 
		record.setMobile(vo.getMobile());// 手机号 
		record.setPassword(vo.getPassword());// 密码 
		record.setCreateTime(vo.getCreateTime());// 创建时间 
			}
		return themapper.updateByPrimaryKeySelective(record);
	}
	
	@Override
	public int remove(Long userId){
		return themapper.deleteByPrimaryKey(userId);
	}
}
